from rest_framework import serializers
from apps.answer.models import Label, Question
from django.db import models

# 标签展示
from apps.users.userserializers import LabelSerializers


class LabelModelSerializer(serializers.ModelSerializer):
    class Meta:
        model = Label
        fields = ('id', 'label_name')


# 用户关注的标签
class UserModelSerializer(serializers.ModelSerializer):
    # users = serializers.ManyToManyField(verbose_name="关注者", write_only=True)
    class Meta:
        model = Label
        fields = ('id', 'label_name')


# 被回答问题列表
class QuestionsModelSerializer(serializers.ModelSerializer):
    user = serializers.StringRelatedField(label='用户')
    labels = LabelSerializers(many=True)

    class Meta:
        model = Question
        fields = ['id', 'createtime', 'labels', 'reply', 'replyname', 'replytime', 'title', 'unuseful_count', 'useful_count', 'user', 'visits']
        # fields = '__all__'



from rest_framework import serializers

from apps.answer.models import Reply


# 问答模型 回答
class ReplyQuestionSerializers(serializers.ModelSerializer):
    class Meta:
        model=Reply
        fields  = '__all__'

################################################################
# 指定标签详情页展示
class LabeldetailModelSerializer(serializers.ModelSerializer):
    # users = serializers.ManyToManyField(verbose_name="关注者", write_only=True)
    questions = QuestionsModelSerializer(many=True)
    users = serializers.PrimaryKeyRelatedField(read_only=True,many=True)
    class Meta:
        model = Label
        fields = "__all__"

